home *** CD-ROM | disk | FTP | other *** search
- package mx.messaging.config
- {
- import flash.utils.describeType;
- import flash.utils.getDefinitionByName;
- import mx.core.mx_internal;
- import mx.messaging.Channel;
- import mx.messaging.ChannelSet;
- import mx.messaging.errors.InvalidChannelError;
- import mx.messaging.errors.InvalidDestinationError;
- import mx.messaging.errors.MessagingError;
- import mx.messaging.messages.IMessage;
- import mx.utils.Translator;
-
- use namespace mx_internal;
-
- public class ServerConfig
- {
- public static var serverConfigData:XML;
-
- public static const CLASS_ATTR:String = "type";
-
- public static const URI_ATTR:String = "uri";
-
- private static const TRANSLATOR:Translator = Translator.getDefaultInstanceFor(ServerConfig);
-
- private static var _channelSets:Object = {};
-
- private static var _clusteredChannels:Object = {};
-
- private static var _unclusteredChannels:Object = {};
-
- public function ServerConfig()
- {
- super();
- }
-
- public static function getProperties(param1:String, param2:String = null) : XMLList
- {
- var destination:XMLList = null;
- var destinationId:String = param1;
- var serviceId:String = param2;
- destination = null;
- if(serviceId == null)
- {
- destination = xml..destination.(@id == destinationId);
- }
- else
- {
- destination = xml[serviceId].destination.(@id == destinationId);
- }
- if(destination.length() > 0)
- {
- return destination.properties;
- }
- throw new InvalidDestinationError(TRANSLATOR.textOf("unknownDestinationForService",serviceId,destinationId));
- }
-
- private static function internalGetChannelSet(param1:XML) : ChannelSet
- {
- var _loc2_:Array = null;
- var _loc3_:XMLList = null;
- var _loc4_:int = 0;
- var _loc5_:int = 0;
- var _loc6_:Boolean = false;
- var _loc7_:String = null;
- var _loc8_:ChannelSet = null;
- _loc2_ = [];
- _loc3_ = param1.channels.channel;
- _loc4_ = int(_loc3_.length());
- _loc5_ = 0;
- while(_loc5_ < _loc4_)
- {
- _loc2_.push(_loc3_[_loc5_].@ref.toString());
- _loc5_++;
- }
- _loc6_ = param1.properties.network.cluster.length() > 0 ? true : false;
- _loc7_ = _loc2_.join(",") + ":" + _loc6_;
- if(_loc7_ in _channelSets)
- {
- return _channelSets[_loc7_];
- }
- _loc8_ = new ChannelSet(_loc2_,_loc6_);
- _channelSets[_loc7_] = _loc8_;
- return _loc8_;
- }
-
- private static function createChannel(param1:String) : Channel
- {
- var channels:XMLList = null;
- var channelConfig:XML = null;
- var className:String = null;
- var uri:String = null;
- var channel:Channel = null;
- var channelClass:Class = null;
- var channelId:String = param1;
- channels = xml.channels.channel.(@id == channelId);
- if(channels.length() == 0)
- {
- throw new InvalidChannelError(TRANSLATOR.textOf("unknownChannelWithId",channelId));
- }
- channelConfig = channels[0];
- className = channelConfig.attribute(CLASS_ATTR).toString();
- uri = channelConfig.endpoint[0].attribute(URI_ATTR).toString();
- channel = null;
- try
- {
- channelClass = getDefinitionByName(className) as Class;
- channel = new channelClass(channelId,uri);
- channel.applySettings(channelConfig);
- }
- catch(e:ReferenceError)
- {
- throw new InvalidChannelError(TRANSLATOR.textOf("unknownChannelClass",className));
- }
- return channel;
- }
-
- public static function getChannel(param1:String, param2:Boolean = false) : Channel
- {
- var _loc3_:Channel = null;
- if(!param2)
- {
- if(param1 in _unclusteredChannels)
- {
- return _unclusteredChannels[param1];
- }
- _loc3_ = createChannel(param1);
- _unclusteredChannels[param1] = _loc3_;
- return _loc3_;
- }
- if(param1 in _clusteredChannels)
- {
- return _clusteredChannels[param1];
- }
- _loc3_ = createChannel(param1);
- _clusteredChannels[param1] = _loc3_;
- return _loc3_;
- }
-
- public static function set xml(param1:XML) : void
- {
- serverConfigData = param1;
- _channelSets = {};
- _clusteredChannels = {};
- _unclusteredChannels = {};
- }
-
- mx_internal static function getChannelSetClusterRequestParams(param1:ChannelSet) : Object
- {
- var _loc2_:String = null;
- var _loc3_:XMLList = null;
- var _loc4_:int = 0;
- var _loc5_:int = 0;
- var _loc6_:XML = null;
- var _loc7_:* = null;
- var _loc8_:XMLList = null;
- var _loc9_:int = 0;
- var _loc10_:int = 0;
- var _loc11_:Object = null;
- var _loc12_:String = null;
- var _loc13_:Array = null;
- _loc2_ = param1.channelIds.join(",");
- if(_loc2_.length > 0)
- {
- _loc3_ = xml..destination;
- _loc4_ = int(_loc3_.length());
- _loc5_ = 0;
- while(_loc5_ < _loc4_)
- {
- _loc6_ = _loc3_[_loc5_];
- if(_loc6_.properties.network.cluster.length() > 0)
- {
- _loc7_ = "";
- _loc8_ = _loc6_.channels.channel.@ref;
- _loc9_ = int(_loc8_.length());
- _loc10_ = 0;
- while(_loc10_ < _loc9_)
- {
- if(_loc10_ > 0)
- {
- _loc7_ += ",";
- }
- _loc7_ += _loc8_[_loc10_].toString();
- _loc10_++;
- }
- if(_loc7_.toString() == _loc2_)
- {
- _loc11_ = {};
- _loc11_.destination = _loc6_.@id.toString();
- _loc12_ = _loc6_.parent().@messageTypes.toString();
- _loc13_ = _loc12_.split(",");
- _loc11_.messageRefType = _loc13_[0];
- return _loc11_;
- }
- }
- _loc5_++;
- }
- }
- return null;
- }
-
- public static function get xml() : XML
- {
- return serverConfigData != null ? serverConfigData : <services/>;
- }
-
- public static function getChannelSet(param1:String, param2:IMessage, param3:String = null) : ChannelSet
- {
- var destinations:XMLList = null;
- var destinationCount:int = 0;
- var alias:String = null;
- var i:int = 0;
- var serviceConfig:XML = null;
- var types:String = null;
- var aliases:Array = null;
- var n:int = 0;
- var j:int = 0;
- var destinationId:String = param1;
- var message:IMessage = param2;
- var serverMessageType:String = param3;
- destinations = xml..destination.(@id == destinationId);
- destinationCount = int(destinations.length());
- if(destinationCount == 0)
- {
- throw new InvalidDestinationError(TRANSLATOR.textOf("unknownDestination",destinationId));
- }
- if(destinationCount == 1)
- {
- return internalGetChannelSet(destinations[0]);
- }
- alias = serverMessageType != null ? serverMessageType : describeType(message).@alias.toString();
- i = 0;
- while(i < destinationCount)
- {
- serviceConfig = destinations[i].parent();
- types = serviceConfig.@messageTypes.toString();
- aliases = types.split(",");
- n = int(aliases.length);
- j = 0;
- while(j < n)
- {
- if(aliases[j] == alias)
- {
- return internalGetChannelSet(destinations[i]);
- }
- j++;
- }
- i++;
- }
- throw new InvalidDestinationError(TRANSLATOR.textOf("destinationWithInvalidMessageType",destinationId,alias));
- }
-
- public static function getServiceIdForMessage(param1:IMessage) : String
- {
- var _loc2_:String = null;
- var _loc3_:XMLList = null;
- var _loc4_:int = 0;
- var _loc5_:int = 0;
- var _loc6_:XML = null;
- var _loc7_:String = null;
- var _loc8_:Array = null;
- var _loc9_:int = 0;
- var _loc10_:int = 0;
- _loc2_ = describeType(param1).@alias.toString();
- _loc3_ = xml.children();
- _loc4_ = int(_loc3_.length());
- _loc5_ = 0;
- while(_loc5_ < _loc4_)
- {
- _loc6_ = _loc3_[_loc5_];
- if(_loc6_.@messageTypes.length() != 0)
- {
- _loc7_ = _loc6_.@messageTypes.toString();
- _loc8_ = _loc7_.split(",");
- _loc9_ = int(_loc8_.length);
- _loc10_ = 0;
- while(_loc10_ < _loc9_)
- {
- if(_loc8_[_loc10_] == _loc2_)
- {
- return _loc6_.localName();
- }
- _loc10_++;
- }
- }
- _loc5_++;
- }
- throw new MessagingError(TRANSLATOR.textOf("noServiceForMessageType",_loc2_));
- }
- }
- }
-
-